'use strict';

import ReactDOM  from 'react-dom';
import React from 'react';
import { browserHistory, hashHistory, Router, Route, Redirect } from 'react-router';
import { StyleRoot } from 'radium';
import useBasename from 'history/lib/useBasename';
import LoginView from './login/LoginView';
import RegisterView from './register/RegisterView';
import { NotFoundView } from 'lightbi-front-widget';
import { ForgetPasswordView } from 'lightbi-front-project';
import { IN_DEPLOY_URI } from 'lightbi-front-utils';

function withBasename(history, dirname) {
  return useBasename(() => history)({ basename: `/${dirname}` })
};

ReactDOM.render((
  <StyleRoot className="full-height">
    <Router history={withBasename(browserHistory, "")} >
      <Route path={IN_DEPLOY_URI == '' ? '/entrance' : IN_DEPLOY_URI + '/entrance'} >
        <Route path="login" component={LoginView} />
        <Route path="register" component={RegisterView} />
        <Route path="forgetPassword" component={ForgetPasswordView} />
        <Route path="404" component={NotFoundView} />
        <Redirect from='*' to='/404' />
      </Route>
    </Router>
  </StyleRoot>),
  document.getElementById("content")
);
